package com.franklin.ideaplugin.api.utils;

import java.util.Arrays;

/**
 * @author Ye Junhui
 * @since 2024/3/22
 */
public class ClassUtils {

    /**
     * 获取包名
     * @param classQualifiedName
     * @return
     */
    public static String getClassPackage(String classQualifiedName){
        String[] split = classQualifiedName.split("\\.");
        String[] strings = Arrays.copyOf(split, split.length - 1);
        return String.join(".",strings);
    }

    /**
     * 获取类名简称
     * @param classQualifiedName
     * @return
     */
    public static String getClassSimpleName(String classQualifiedName){
        String[] split = classQualifiedName.split("\\.");
        return split[split.length - 1];
    }

    /**
     * 获取类不包含泛型
     * @param classQualifiedName
     * @return
     */
    public static String getClassNameWithoutGeneric(String classQualifiedName){
        int index = classQualifiedName.indexOf('<');
        if (index > 0){
            return classQualifiedName.substring(0,index);
        }
        return classQualifiedName;
    }
}
